package com.njupt.LinkTable;

/**
 * @Author: wujiaming
 * @CreateTime: 2025/2/18 10:37
 * @Description: 141. 环形链表
 * @Version: 1.0
 */


public class HasCycle_141 {

    public boolean hasCycle(ListNode head) {
        if(head == null || head.next == null){
            return false;
        }
        ListNode slow = head;
        ListNode fast = head.next;
        while(fast != slow){
            if(fast == null || fast.next == null){
                return false;
            }
            slow = slow.next;
            fast = fast.next.next;
        }
        return true;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(3);
//        ListNode node1 = new ListNode(2);
//        ListNode node2 = new ListNode(0);
//        ListNode node3 = new ListNode(-4);
//        head.next = node1; node1.next = node2;node2.next = node3; node3.next = node1;

        HasCycle_141 test = new HasCycle_141();
        System.out.println(test.hasCycle(head));
    }
}
